package xuegao.study.mall.admin.controller;

import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import xuegao.study.mall.admin.feign.JobClient;
import xuegao.study.mall.common.api.CommonResult;
import xuegao.study.mall.common.model.job.SysJob;

import java.util.List;

@RestController
@RequestMapping("/job")
public class JobController {

    @Autowired
    private JobClient jobClient;

    @ApiOperation("新增任务")
    @PostMapping(value = "/addJob")
    public CommonResult addJob(@RequestBody SysJob sysJob) {
        return jobClient.addJob(sysJob);
    }

    @ApiOperation("删除任务")
    @PostMapping(value = "/deleteJob/{id}")
    public CommonResult deleteJob(@PathVariable Long id) {
        return jobClient.deleteJob(id);
    }

    @ApiOperation("修改定时表达式")
    @PostMapping("/reScheduleJob/{id}")
    public CommonResult updateByBean(@PathVariable Long id, @RequestParam String jobCron, @RequestParam String jobDescribe) {
        return jobClient.updateByBean(id, jobCron, jobDescribe);
    }

    @ApiOperation("变更任务执行状态")
    @PostMapping(value = "/changeState/{id}")
    public CommonResult changeState(@PathVariable Long id) {
        return jobClient.changeState(id);
    }

    @ApiOperation("任务列表")
    @GetMapping(value = "/queryList")
    public CommonResult<List<SysJob>> queryList() {
        return jobClient.queryList();
    }



}
